package p2;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-09-16
 * Time: 13:04
 */

//TCP回显服务器 服务端


//ServerSocket和Socket
public class TCPEchoServer {
    ServerSocket ServerSocket = null;

    public TCPEchoServer(int port) throws IOException {
        ServerSocket = new ServerSocket(port);
    }

    //启动服务器
    public void start() throws IOException {
        while (true) {
            Thread t = new Thread(() -> {
                try {
                    Socket ClientSocket = ServerSocket.accept();//ServerSocket去接电话,接到电话给Socket处理
                    processConnection(ClientSocket);//处理
                } catch (IOException e) {
                    e.printStackTrace();
                }
            });
            t.start();
        }
    }

    private void processConnection(Socket clientSocket) {
        System.out.println("客户端上线");

        Scanner scanner = new Scanner(System.in);


    }


}
